package com.neusoft.yuejian26.yuejian_26.Adapter;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.neusoft.yuejian26.yuejian_26.Bean.Replay;
import com.neusoft.yuejian26.yuejian_26.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2017/10/31 0031.
 */

public class ReplyAdapter extends XRecyclerView.Adapter<XRecyclerView.ViewHolder> {
    private Context mContext;
    protected List mDataList;
    private LayoutInflater mlayoutInflater;
    public ReplyAdapter(Context mContext, List<Replay> mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mlayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public XRecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mlayoutInflater.from(parent.getContext()).inflate(R.layout.replylist_item, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(XRecyclerView.ViewHolder holder, int position) {
        final Replay entity = (Replay) mDataList.get(position);
        if (null == entity)
            return;
        ReplyAdapter.ViewHolder viewHolder = (ReplyAdapter.ViewHolder) holder;
        viewHolder.reply_list_uname.setText(entity.getUname());
        viewHolder.reply_list_content.setText(entity.getRptext());
        Picasso.with(mContext)
                .load("http://115.159.93.244/new18yuejian/Public/upload/"+entity.getUserpic())
                .into(viewHolder.reply_list_upic);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    private class ViewHolder extends XRecyclerView.ViewHolder {
        TextView reply_list_uname,reply_list_content;
        ImageView reply_list_upic;
        CardView replyitem;
        public ViewHolder(View v) {
            super(v);
            reply_list_uname = (TextView) v.findViewById(R.id.reply_list_uname);
            reply_list_content= (TextView) v.findViewById(R.id.reply_list_content);
            reply_list_upic = (ImageView) v.findViewById(R.id.reply_list_upic);
            replyitem = (CardView) v.findViewById(R.id.repy_item_card);
        }
    }

}
